package com.per.yyyFrame.config;

import com.per.yyyFrame.common.JsonView;
import com.per.yyyFrame.common.ServerResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: yyy
 * Date: 2022/2/7
 * Time: 15:34
 * Description:
 */
@ControllerAdvice
public class GlobalExceptional  {
  @ExceptionHandler(value = BizExceptional.class)
  public JsonView exceptionHandler(Exception e) throws Exception {
    BizExceptional bizex=(BizExceptional)e;
    ModelAndView modelAndView=new ModelAndView();

    if(bizex.getErrorMsgList().size()>0){

//      Map map=new HashMap();
//      map.put("data",bizex.getErrorMsgList().get(0));
      System.out.println("--------------:"+bizex.getErrorMsgList().get(0));
      JsonView jsonView=new JsonView(bizex.getErrorMsgList().get(0));
      //modelAndView.addObject("errorMessage",bizex.getErrorMsgList().get(0));
      //modelAndView.setViewName("success");

      return jsonView;
    }
    return null;
  }
}
